package com.autumn.xa.common.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;

import java.util.Arrays;

/**
 * ClassName: FrameworkUtils
 *
 * @Description:
 * @Author: wangqiuyang
 * @Date: 2021/12/28 下午5:31
 * History:
 * <author>          <time>          <version>          <desc>
 * wangqiuyang    2021/12/28 下午5:31   @Version 1.0        描述
 */
public class FrameworkUtils {

    /**
    * Description: 获取系统名称
    * @param contxt
    * @return: java.lang.String
    * @author: wangqiuyang
    * @Date: 2022/1/25 11:17 上午
    */
    public static String getOsName(ApplicationContext contxt) {
        ConfigurableEnvironment environment = (ConfigurableEnvironment) contxt.getEnvironment();
        return environment.getProperty("os.name");
    }

    /**
    * Description: 获取系统名称
    * @param environment
    * @return: java.lang.String
    * @author: wangqiuyang
    * @Date: 2022/1/25 11:17 上午
    */
    public static String getOsName(Environment environment) {
        return ((ConfigurableEnvironment)environment).getProperty("os.name");
    }

    public static void printAllBeanNames(AnnotationConfigApplicationContext context) {
        System.out.println("-----------------> 打印所有的bean 开始");

        // 获取所有的bean名称
        String[] beanDefinitionNames = context.getBeanDefinitionNames();

        // 打印所有
        Arrays.stream(beanDefinitionNames).forEach(System.out::println);

        System.out.println("-----------------> 打印所有的bean 结束");
    }
}
